import java.io.File;
import java.util.Comparator;


public class FileCmp implements Comparator<File> {

	private String sortType;
	public FileCmp(String sortType){
		this.sortType = sortType;
	}

	@Override
	public int compare(File file1, File file2) {
		switch(sortType){
		case "size":return (file1.length() > file2.length())? 1: ((file1.length() < file2.length())? -1: 0);
		case "name":return file1.toString().compareTo(file2.toString());
		case "lastMod":return (file1.lastModified() > file2.lastModified())? 1: ((file1.lastModified() < file2.lastModified())? -1: 0);
		default: return file1.toString().compareTo(file2.toString());
		}
	}
}
